#include <iostream>
#include <string>
#include <memory>
class Fruit
{

public:
    virtual void getname() = 0;
};

class Banana : public Fruit
{
public:
    void getname() override
    {
        std::cout << "我是一个香蕉" << std::endl;
    }
};

class Apple : public Fruit
{
public:
    void getname() override
    {
        std::cout << "我是一个苹果" << std::endl;
    }
};

class Factory
{

public:
  Factory(){}
    static Factory& getinstance(){
     static Factory f;
     return f;
    } 

    std::shared_ptr<Fruit> build(const std::string &name)
    {

        if (name == "香蕉")
        {
            return std::shared_ptr<Banana>(new Banana());
        }

        else if (name == "苹果")
        {
            return std::shared_ptr<Apple>(new Apple ());
        }
        else
        {
            return std::shared_ptr<Fruit>(); // 返回空
        }
    }

    // 禁用拷贝构造与赋值重载：
    Factory(const Factory &) = delete;
    Factory operator=(const Factory &) = delete;
};
int main()
{
    Factory:: getinstance().build("苹果")->getname();
    Factory:: getinstance().build("香蕉")->getname();
    return 0;
}
